package com.amap.api.col.s;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import com.amap.api.col.s.cf;
import com.amap.api.col.s.y;
import com.amap.api.services.auto.AutoTChargeStationResult;
import com.amap.api.services.auto.AutoTSearch;
import com.amap.api.services.core.AMapException;
import com.amap.api.services.interfaces.IAutoTSearch;

/* compiled from: AutoTSearchCore.java */
/* loaded from: classes.dex */
public final class bf implements IAutoTSearch {
    private Context a;
    private Handler b;
    private AutoTSearch.Query c;
    private AutoTSearch.OnChargeStationListener d;

    public bf(Context context) throws AMapException {
        this.b = null;
        cg a = cf.a(context, m.a(false));
        if (a.a != cf.c.SuccessCode) {
            throw new AMapException(a.b, 1, a.b, a.a.a());
        }
        this.a = context.getApplicationContext();
        this.b = y.a();
    }

    @Override // com.amap.api.services.interfaces.IAutoTSearch
    public final void setQuery(AutoTSearch.Query query) {
        this.c = query;
    }

    @Override // com.amap.api.services.interfaces.IAutoTSearch
    public final void setChargeStationListener(AutoTSearch.OnChargeStationListener onChargeStationListener) {
        this.d = onChargeStationListener;
    }

    @Override // com.amap.api.services.interfaces.IAutoTSearch
    public final AutoTChargeStationResult searchChargeStation() throws AMapException {
        try {
            w.a(this.a);
            AutoTSearch.Query query = this.c;
            if (query == null) {
                throw new AMapException(AMapException.AMAP_CLIENT_INVALID_PARAMETER);
            }
            return new b(this.a, query.m11clone()).c();
        } catch (AMapException e) {
            throw new AMapException(e.getMessage());
        }
    }

    @Override // com.amap.api.services.interfaces.IAutoTSearch
    public final void searchChargeStationAsync() {
        try {
            ax.a().a(new Runnable() { // from class: com.amap.api.col.s.bf.1
                {
                    bf.this = this;
                }

                @Override // java.lang.Runnable
                public final void run() {
                    y.a aVar;
                    Message obtainMessage = bf.this.b.obtainMessage();
                    obtainMessage.arg1 = 20;
                    obtainMessage.what = 600;
                    Bundle bundle = new Bundle();
                    AutoTChargeStationResult autoTChargeStationResult = null;
                    try {
                        try {
                            autoTChargeStationResult = bf.this.searchChargeStation();
                            bundle.putInt("errorCode", 1000);
                            aVar = new y.a();
                        } catch (AMapException e) {
                            bundle.putInt("errorCode", e.getErrorCode());
                            aVar = new y.a();
                        }
                        aVar.b = bf.this.d;
                        aVar.a = autoTChargeStationResult;
                        obtainMessage.obj = aVar;
                        obtainMessage.setData(bundle);
                        bf.this.b.sendMessage(obtainMessage);
                    } catch (Throwable th) {
                        y.a aVar2 = new y.a();
                        aVar2.b = bf.this.d;
                        aVar2.a = autoTChargeStationResult;
                        obtainMessage.obj = aVar2;
                        obtainMessage.setData(bundle);
                        bf.this.b.sendMessage(obtainMessage);
                        throw th;
                    }
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
